<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	 Object sessionTime  = request.getSession().getAttribute("orders_time_start");
	  
	
%>
<!DOCTYPE html >
<html>
<head>
</head>
<c:if test="${code==1}">
	 <script type="text/javascript">
	 	
	
		var interval;  //定时器
		
		$(function() {
		     $('#outside_div').mousemove(function(){
	/* 	 		$("#my_audio")[0].pause();  //暂停
		 		$("#my_audio")[0].load();  //重载 */
	         }); 
	         
		    
		     //定时器标记
		     var  ordersTimeStart= "<%=sessionTime%>"+""; 
		     if(ordersTimeStart!=null&&ordersTimeStart=="true"){   //如果标记为开启
		    	 run(); //加载页面时启动定时器  
		     }else{    //如果标记为关闭
		    		//定时器按钮显示关闭效果
		    		 clearTimeout(interval);
					$("#timeOutControll").attr("class", "delete");
					$("#timeOutControll").find('span').text('已关闭定时器');
		     }
			
			 function run() {
				clearTimeout(interval);
				interval = setInterval(chat, "30000");
			 }
			 
/* 			 if(audioPlay){    //判断全局变量标记，是否播放 ,变量放在<script src="jsutil/static.js"" type="text/javascript">
				 $("#my_audio")[0].play();
			 } */
		});
		
		//定时器执行内容
		function chat() {
			var len =$("#searchOrders_div_interval").length;
			if(len>0){
				$.ajax({
					type:'post',
					url:'<%=basePath%>ifNewOrderIncome',
					success : function(data) {
						if (data == 'true') { //有新订单，播放音乐
							audioPlay=true;  
							$("#searchOrders_search").submit();  //刷新表单
						} else if (data == 'false') { //无新订单
							audioPlay=false;
						}
					}
				});
			}else{
				clearTimeout(interval);  //取消定时器
			}
		}

		//定时器开关
		function timeOutControll(obj) {
			if ($(obj).attr("class") == "add") {//关闭定时器  
				clearTimeout(interval);
				$(obj).attr("class", "delete");
				$(obj).find('span').text('已关闭定时器');
			} else if ($(obj).attr("class") == "delete") { //开启定时器  
				interval = setInterval(chat, "30000");
				$(obj).attr("class", "add");
				$(obj).find('span').text('已开启定时器');
			}
		}
		
		function dealOrder(obj)
		{
			
			if(obj!=null)
			{
				 var dealStatus=0;
				if(obj.innerHTML=='已处理')
					{
					dealStatus=0;
					}
				if(obj.innerHTML=='未处理')
					{
					dealStatus=1;
					}
				$.ajax({
					type:'post',
					url:'<%=basePath%>dealCourierContent',
				    data: {id:obj.id,dealStatus:dealStatus},
					success : function(data) {
						if (data == 'true') { //处理成功
							if(obj.innerHTML=='已处理')
							{	 $(obj).css("color","red");
								 $(obj).text('未处理');
							}else
							{
							 $(obj).css("color","gray");
							 $(obj).text('已处理');
							}
						} else if (data == 'false') { 
							alert(data);
						}
					}
				});
			}
		}
		
		function flagOrderDeduct(obj)
		{
			var orderId=obj.id.substring(11, obj.id.length);
			if(obj!=null)
			{
				 var deductFlag=0;
				if(obj.innerHTML=='检查扣钱')
					{
					deductFlag=1;
					}
				if(obj.innerHTML=='不检查扣钱')
					{
					deductFlag=0;
					}
				$.ajax({
					type:'post',
					url:'<%=basePath%>flagOrderDeduct',
				    data: {id:orderId,deductFlag:deductFlag},
					success : function(data) {
						if (data == 'true') { //处理成功
							if(obj.innerHTML=='检查扣钱')
							{	 $(obj).css("color","red");
								 $(obj).text('不检查扣钱');
							}else
							{
							 $(obj).css("color","gray");
							 $(obj).text('检查扣钱');
							}
						} else if (data == 'false') { 
							alert(data);
						}
					}
				});
			}
		}
	</script> 
<body >
<div id="searchOrders_div_interval"></div>

	<div id="outside_div">

<%-- 		 <audio id="my_audio" src="<%=basePath%>music/music.mp3" controls="controls" loop hidden="true">
		</audio>  --%>


		<form id="pagerForm" method="post" action="courierContentAction.action?toResult=courierContentOrders&rightId=${rightId}">
			<input type="hidden" name="pageNum" value="${page.currentPage }" /> 
			<input type="hidden" name="pageSize" value="${page.pageSize }" />
			<input type="hidden" name="orderNo" value="${orderNo}" />
			<input type="hidden" name="courierId" value="${courierId}" />
			<input type="hidden" name="selectDealFlag" value="${selectDealFlag}" />
		</form>

		<form id="searchOrders_search" onsubmit="return navTabSearch(this);" action="courierContentAction.action?toResult=courierContentOrders&rightId=${rightId}" method="post">
			<div class="pageHeader">

				<input type="hidden" name="init" value=0>
				<div class="searchBar">
					<table class="searchContent">

						<tr>
						<td>基础订单号: <input type="text" name="orderNo" style="width:100px;" value="${orderNo}"/>
						</td>
							
						<td>快递员:</td>
						<td>
						<a class="btnLook"	href="kuaidituCourierLookUp" lookupGroup="courier"  width="1000" height="580" warn="请选择快递员" >查找带回</a>
								<input id="courierName_Search" bringBackName="courier.courierName" value="${courierName}" type="text" name="courierName" readonly="readonly" style="width:100px;"/>
								<input id="courierId_Search" bringBackName="courier.courierId" type="hidden"  readonly="readonly" Name="courierId" value="${courierId}" />
						</td>
						<td>是否处理: 
							<select name="selectDealFlag" id="dealFlag">
							<option  value="0" <s:if test="#request.selectDealFlag==0">selected="selected"</s:if> >未处理</option>
							<option  value="1" <s:if test="#request.selectDealFlag==1">selected="selected"</s:if> >已处理</option>
							<option  value="2"<s:if test="#request.selectDealFlag==2">selected="selected"</s:if> >全部</option>	
							</select>
							
						</td>
						
						
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
							
							<td>
								<div class="buttonActive">
									<div class="buttonContent">
										<button type="submit">检索</button>
									</div>
								</div>
							</td>
							
						
						</tr>
					</table>
				</div>
			</div>
			<div class="pageContent">
				<div class="panelBar">
					<ul class="toolBar">
						<c:forEach items="${righSubtList}" var="rightsub">
							<!-- 添加  
						<c:if test="${fn:contains(rightsub.rightValue,'addCourier')}">
							<li><a class="add" href="${rightsub.rightValue}&rightId=${rightId}" target="navTab"><span>${rightsub.rightName}</span> </a>
							</li>
							<li class="line">line</li>
						</c:if>-->
						</c:forEach>
						<%-- <li><a id="timeOutControll" class="add" href="javascript:void(0)" onclick="timeOutControll(this)"><span>已开启定时器</span> </a></li>
						<li class="line">line</li> --%>
					</ul>
				</div>
				<table class="list" width="100%" layoutH="138">
					<thead>
						<tr>
							<th align="center">序号</th>
							<th align="center">小订单号</th>
							<th align="center">当前订单分配快递员</th>
							<th align="center">提交内容</th>
							<th align="center">提交时间</th>
							<th align="center">处理</th>
							<th align="center">标记不扣钱</th>
						</tr>
					</thead>
					<tbody>
						<s:iterator var="orders" value="page.data" status="st">
							<tr target="sid_support" rel="<s:property value="#orders.id" />">
								<th width="1%" align="center"><s:property value="page.pageSize * (page.currentPage-1) + #st.index + 1" /></th>
								<th width="3%" align="left"><s:property value="#orders.orderNo" /></th>
								 <th width="3%" align="left"><s:property value="#orders.courierName" /></th>
								 <th width="10%" align="left"><s:property value="#orders.courierContent" /></th>
								<th width="5%" align="center"><s:date name='#orders.courierContentTime' format='yyyy-MM-dd HH:mm:ss' /></th>
								<%-- <th width="5%" align="left"><s:property value="#orders.content" /></th> --%>
								<th width="4%" align="left">
								<s:if test="#orders.courierContentDealFlag==null">
									<a id="<s:property value="#orders.id" />" href="javascript:void(0)" onclick="dealOrder(this)" style="color: Red">未处理</a></s:if> 
									<s:elseif test="#orders.courierContentDealFlag==1">
									<a id="<s:property value="#orders.id" />"   href="javascript:void(0)" onclick="dealOrder(this)" style="color: gray;">已处理</a></s:elseif>
									<s:elseif test="#orders.courierContentDealFlag==0">
									<a id="<s:property value="#orders.id" />"   href="javascript:void(0)" onclick="dealOrder(this)"  style="color: Red">未处理</a>
								  </s:elseif>
								<th width="4%" align="left">
							 		<s:if test="#orders.deductFlag==null">
										<a id="deductFlag_<s:property value="#orders.id" />" href="javascript:void(0)" onclick="flagOrderDeduct(this)" style="color: gray">检查扣钱</a></s:if> 
									<s:elseif test="#orders.deductFlag==1">
										<a id="deductFlag_<s:property value="#orders.id" />"   href="javascript:void(0)" onclick="flagOrderDeduct(this)" style="color: Red;">不检查扣钱</a></s:elseif>
									<s:elseif test="#orders.deductFlag==0">
										<a id="deductFlag_<s:property value="#orders.id" />"   href="javascript:void(0)" onclick="flagOrderDeduct(this)"  style="color: gray">检查扣钱</a>
								  	</s:elseif>
								</th>
							</tr>
							
						</s:iterator>
					</tbody>
				</table>
				<div class="panelBar">
					<div class="pages">
						<span>共${page.totalNum }条，共${page.totalPage }页</span>
					</div>
					<div class="pagination" targetType="navTab" totalCount="${page.totalNum }" numPerPage="${page.pageSize }" pageNumShown="10" currentPage="${page.currentPage }"></div>
				</div>
			</div>
		</form>


	</div>
	</body>
</c:if>
<c:if test="${code==0}">
${message}
</c:if>
</html>